import React from "react";
import store from "../../store/store";
import {incrementAction,decrementAction ,equalityAction} from '../../store/actions/countAction'
export default function Count() {
  const {count} = store.getState().count
  const accumulation = () => {
    store.dispatch(incrementAction(1))
  }
  const accumulateMinus = () => {
    store.dispatch(decrementAction(1))
  }
  const ifOddDecrementHandle = () => {
    if(count % 2 !== 0){
      store.dispatch(incrementAction(1))
    }
  }
  const waitDecrementHandle = () => {
    store.dispatch(equalityAction(1))
  }
  return (
    <div>
      <h1>我是Count组件，我的值是{count}</h1>
      <button onClick={accumulation}>累加</button>
      <button onClick={accumulateMinus}>累减</button>
      <button onClick={ifOddDecrementHandle}>如果是奇数再加1</button>
      <button onClick={waitDecrementHandle}>等2s再加1</button>
    </div>
  );
}
